<template>
    <div id="wai">
        <div class="nei">
            <h1 class="title">{{ msg }}</h1>
            <div class="news">
                <p>名称：{{ goods_news['name'] }}</p>
                <p>单价：{{ goods_news['order_price'] }}￥</p>
                <p>数量：{{ goods_news['count'] }}件</p>
                <p>收货地址：{{ goods_news['province'] }}-{{ goods_news['detailed_address'] }}</p>
                <p>联系电话：{{ goods_news['phone_number'] }}</p>
                <p>创建时间：{{ goods_news['create_time'] }}</p>
                <p>总价：{{ goods_news['order_price'] * goods_news['count'] }}￥</p>
                <p>订单状态：{{ showText(goods_news['user_is_payment'], goods_news['user_is_cancel'],
                    goods_news['shller_is_cancle'], goods_news['is_send_out_goods']) }}</p>
                <button @click="cancel_order" :disabled="flag" class="cancel_order">取消订单</button>
                <button @click="ensure_send_out_goods" :disabled="flag" class="cancel_order">确认发货</button>
                <button @click="deblocking" class="cancel_order">{{ change_but_text }}</button>
            </div>
        </div>
    </div>
</template>
                  
<script>

export default {
    data() {
        return {
            msg: '订单详情',
            session_id:this.$auth.getAuthorization(),
            goods_news:{},
            order_id:this.$route.params.id,
            change_but_text: '解锁',
            flag: true
        }
    },
    methods: {
        //获取订单信息
        get_orders_list() {
            this.$http.post('get_order_info.php', { 'session_id': this.session_id,'order_id':this.order_id },
                {
                    headers: {
                        'Content-Type': 'application/json' // 设置请求头
                    }
                }).then(response => {
                    if (response.data.status === 1) {
                        // alert(response.data.message);
                        console.log(response.data.data);
                        this.goods_news = response.data.data;
                    } else {
                        // alert(response.data.message);
                        console.log(response.data.message);
                    }
                })
                .catch(error => {
                    console.error(error);
                });
        },
        //解锁
        deblocking() {
            this.flag = !this.flag;
            this.change_but_text = this.flag ? '解锁' : '锁定';
        },
        //订单状态
        showText(a, b, c, d) {
            if (a == 0) {
                return '未支付';
            } else if (a == 1 && b == 0 && c == 0 && d == 0) {
                return '未发货';
            } else if (a == 1 && b == 0 && c == 0 && d == 1) {
                return '已发货';
            } else if (a == 1 && b == 0 && c == 1 && d == 0) {
                return '商家取消了订单';
            } else if (a == 1 && b == 0 && c == 1 && d == 1) {
                return '商家取消了订单，已发货';
            } else if (a == 1 && b == 1 && c == 0 && d == 0) {
                return '用户取消的订单';
            } else if (a == 1 && b == 1 && c == 0 && d == 1) {
                return '用户取消了订单，已发货';
            } else if (a == 1 && b == 1 && c == 1 && d == 0) {
                return '用户与商家都取消了订单';
            } else if (a == 1 && b == 1 && c == 1 && d == 1) {
                return '用户与商家都取消了订单，已发货';
            }
        },
        //取消订单
        cancel_order(){
            this.$http.post('seller_cancel_order.php', { 'session_id': this.session_id,'order_id':this.order_id },
                {
                    headers: {
                        'Content-Type': 'application/json' // 设置请求头
                    }
                }).then(response => {
                    if (response.data.status === 1) {
                        // alert(response.data.message);
                        // this.goods_news = response.data.data;
                        console.log(response.data.message);
                        this.get_orders_list();
                    } else {
                        alert(response.data.message);
                        // console.log(response.data.message);
                    }
                })
                .catch(error => {
                    console.error(error);
                });
        },
        //发货
        ensure_send_out_goods(){
            this.$http.post('ensure_send_out_goods.php', { 'session_id': this.session_id,'order_id':this.order_id },
                {
                    headers: {
                        'Content-Type': 'application/json' // 设置请求头
                    }
                }).then(response => {
                    if (response.data.status === 1) {
                        // alert(response.data.message);
                        // this.goods_news = response.data.data;
                        console.log(response.data.message);
                        this.get_orders_list();
                    } else {
                        // alert(response.data.message);
                        console.log(response.data.message);
                    }
                })
                .catch(error => {
                    console.error(error);
                });
        }
        
    },
    watch: {

    },
    created(){
        this.get_orders_list();
    }
}
</script>
  
  <!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
#wai {
    .nei {
        .title {
            font-size: 50px;
            margin-top: 2%;
        }

        .news {
            padding-left: 25%;
            padding-top: 5%;

            p {
                font-size: 30px;
                margin-top: 3%;
                color: black;
            }

            .cancel_order {
                width: 150px;
                height: 50px;
                margin-top: 3%;
                margin-left: 2%;
            }
        }

    }
}
</style>
                                                                          